package com.itjeffrey.autocode.controller;

import com.itjeffrey.autocode.bo.ResInfoTbBO;
import com.itjeffrey.autocode.bo.req.ChangeAuthBO;
import com.itjeffrey.autocode.bo.req.IsEnableBO;
import com.itjeffrey.autocode.common.Result;
import com.itjeffrey.autocode.service.ResInfoTbService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 控制器类
 * @author: admin
 * @date: 2021-03-28 12:35:25
 */
@RestController
@RequestMapping("/res/info")
public class ResInfoTbController {

    @Resource
    private ResInfoTbService resInfoTbService;

    @RequestMapping("/add")
    public ResponseEntity<Result> add(@RequestBody @Valid ResInfoTbBO resInfoTbBO){
        return ResponseEntity.ok(resInfoTbService.add(resInfoTbBO));
    }

    @RequestMapping("/mod")
    public ResponseEntity<Result> mod(@RequestBody @Valid ResInfoTbBO resInfoTbBO){
        return ResponseEntity.ok(resInfoTbService.mod(resInfoTbBO));
    }

    @RequestMapping("/delete/{id}")
    public ResponseEntity<Result> delete(@PathVariable("id") Integer id){
        return ResponseEntity.ok(resInfoTbService.delete(id));
    }

    @RequestMapping("/query")
    public ResponseEntity<Result> queryList(@RequestBody @Valid ResInfoTbBO resInfoTbBO){
        return ResponseEntity.ok(resInfoTbService.queryList(resInfoTbBO));
    }

    @RequestMapping("/query/{id}")
    public ResponseEntity<Result> queryOne(@PathVariable("id") Integer resId){
        return ResponseEntity.ok(resInfoTbService.queryOne(resId));
    }

    /**
     * 查询资源权限
     * @param resInfoTbBO
     * @return
     */
    @RequestMapping("/queryAuthrizeResource")
    public ResponseEntity<Result> queryAuthrizeResource(@RequestBody ResInfoTbBO resInfoTbBO){
        return ResponseEntity.ok(resInfoTbService.queryAuthrizeResource(resInfoTbBO));
    }

    /**
     * 修改资源权限
     * @param changeAuthBO
     * @return
     */
    @RequestMapping("/changeAuth")
    public ResponseEntity<Result> changeAuth(@RequestBody @Valid ChangeAuthBO changeAuthBO){
        return ResponseEntity.ok(resInfoTbService.changeAuth(changeAuthBO));
    }

    /**
     * 资源是否启用
     * @param isEnableBO
     * @return
     */
    @PostMapping("/isEnable")
    public ResponseEntity<Result> isEnable(@RequestBody IsEnableBO isEnableBO){
        return ResponseEntity.ok(resInfoTbService.isEnable(isEnableBO));
    }
}